﻿/* -------------------------------------------------------------------------
//  File        :   tiles_pool.h
//  Author      :   Sum
//  Datet       :   2014/4/15 14:49
//  Brief       :   
//
// -----------------------------------------------------------------------*/
#ifndef __TILES_POOL_H_
#define __TILES_POOL_H_

#include "hgesprite.h"
#include <map>
#include "Singleton.h"

#define TILES_SIZE  32

class tiles_pool_x
{
public:
    tiles_pool_x();
    ~tiles_pool_x();

    BOOL init(HGE* pHge, LPCTSTR lpszFilePath);
    BOOL uninit();
    hgeSprite* get(int nId);
    int getTilesNum();

private:
    typedef struct _tiles_pool_item
    {
        _tiles_pool_item()
        {
            nId = 0;
            x = 0;
            y = 0;
            nWidth = nHeigth = TILES_SIZE;
        }

        int nId;
        int x;
        int y;
        int nWidth;
        int nHeigth;
        CString cstrPath;
    }tiles_pool_item;

private:
    BOOL _parseTilesXml(LPCTSTR lpszFilePath);
    BOOL _parseTilesXmlItem(tiles_pool_item& item, TiXmlElement* pNote);
    hgeSprite* _createSprite(tiles_pool_item& item);
    BOOL _insertItem(tiles_pool_item& item, hgeSprite* pSprite);

private:
    CString m_cstrGameFilePath;
    HGE* m_pHGE;
    std::map<int, hgeSprite*> m_tiles_map;
};

typedef Singleton<tiles_pool_x> tiles_pool;

#endif // __TILES_POOL_H_